from django.http import JsonResponse
from django.shortcuts import render


def chart_list(request):
    """ 数据统计页面 """
    return render(request, 'chart_list.html')


def chart_bar(request):
    """ 构造柱状图数据 """
    # 数据可以从数据库中获取
    legend = ["京东", "淘宝"]
    series_list = [
        {
            "name": '京东',
            "type": 'bar',
            "data": [5, 20, 36, 10, 10, 20]
        },
        {
            "name": '淘宝',
            "type": 'bar',
            "data": [4, 12, 14, 20, 17, 15]
        }
    ]
    x_axis = ['一月', '二月', '三月', '四月', '五月', '六月']
    # JSON序列化
    result = {
        "status": True,
        "data": {
            'legend': legend,
            'series_list': series_list,
            'x_axis': x_axis,
        }
    }
    return JsonResponse(result)


def chart_pie(request):
    series_data = [
        {'value': 1048, "name": 'IT部门'},
        {"value": 735, "name": '新媒体'},
        {"value": 580, "name": '策划部'},
    ]
    result = {
        "status": True,
        "data": series_data,
    }
    return JsonResponse(result)


def chart_line(request):
    x_axis = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    series_data = [150, 230, 224, 218, 135, 147, 260]
    result = {
        "status": True,
        "data": {
            "series_data": series_data,
            "x_axis": x_axis,
        },
    }
    return JsonResponse(result)
